/*
 * Literal.cpp
 *
 * Copyright 2012 Fabian Wenzelmann
 *
 * This file is part of Recognition-Procedures-for-Boolean-Functions.
 *
 * Recognition-Procedures-for-Boolean-Functions is free software: you
 * can redistribute it and/or modify it under the terms of the
 * GNU General Public License as published by the Free Software Foundation,
 * either version 3 of the License, or (at your option) any later version.
 *
 * Recognition-Procedures-for-Boolean-Functions is distributed in the hope
 * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
 * Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Recognition-Procedures-for-Boolean-Functions.
 *
 * If not, see <http://www.gnu.org/licenses/>.
 */

#include "bfr/Literal.hpp"

#include <iostream>
#include <string>
#include <sstream>

#include <boost/functional/hash.hpp>

namespace bfr {

Literal::Literal(const size_t i, const bool p)
    : id(i), polarity(p) { }

Literal::Literal(const Literal &other)
    : id(other.getId()), polarity(other.getPolarity()) { }

Literal::Literal()
    : id(-1), polarity(false) { }

Literal::~Literal() { }

std::string Literal::variableString() const {
    std::ostringstream stream;
    variableString(stream);
    return stream.str();
}

std::string Literal::asString() const {
    std::ostringstream stream;
    stream << *this;
    return stream.str();
}

size_t Literal::hashValue() const {
    size_t seed = 0;
    boost::hash_combine(seed, polarity);
    boost::hash_combine(seed, id);
    return seed;
}

std::ostream& operator<<(std::ostream& os, const Literal &l) {
    if (!l.polarity) {
        os << Literal::NEG_SYMBOL;
    }
    l.variableString(os);
    return os;
}

size_t hash_value(const Literal &literal) {
    return literal.hashValue();
}

} // namespace bfr
